﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="CercaAnnunci.aspx.vb" Inherits="TecnoHouse.CercaAnnunci" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function() {
            var skipLimit = 0;
            var tot = 0;
            var getannunci = function(){ 
                $takeLimit = (skipLimit == 0 && tot > 0) ? tot : <%=annunciLimit %>; //Se abbiamo azzerato lo skipLimit, li riprendiamo tutti
                $.getJSON("/BLL/hndSearch.ashx", 
                { op: "GetAnnunci", skipLimit: skipLimit, takeLimit: $takeLimit, contratto: <%=contratto %>, immobile: <%=immobile %>,
                    prezzoDa: <%=prezzoDa %>, prezzoA: <%=prezzoA %>, comune: <%=comune %>, orderby: $("#orderby").val()},
                   function(data) {
                       if (data != "0") { 
                            $.tmpl("annuncio", data, {
                               formatPrice: function(price){
                                   switch(price)
                                    {
                                        case 0:
                                            return "Trattativa in sede";
                                        break;
                                        case 1:
                                            return "Prezzo affare";
                                        break;
                                        default: 
                                            return "€ " + $().number_format(price, { numberOfDecimals: 2 });
                                        break;
                                    }
                                }
                            }).appendTo("#searchresults");
                            skipLimit += $takeLimit;
                            tot += $takeLimit;
                            /*$(".price").each(function(i){
                                $val = $(this).text();
                                $val = $().number_format($val, { numberOfDecimals: 2 });
                                $(this).text($val).removeClass("price");
                            });*/
                            $("span").tipsy({gravity:"n", live:true}); 
                       }
                       else
                            $("#searchresults").empty().append("<li class='noresults'>La ricerca non ha prodotto risultati</li>");
                   }
               );
            };
            //FIRST CALL ONLOAD
            getannunci();
            
            $("#orderby").change(function(){
                $("#searchresults").empty();
                skipLimit = 0;
                getannunci();
            });    
            
            $("#btnmore").click(function(){
                getannunci();
            });    
            
            $(".loading").ajaxStart(function(){
                $(this).fadeIn();
            }).ajaxStop(function(){
                $(this).fadeOut();
            });                    
                    
        });
        
        
   </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
    <h3><span class="icon search"></span><span><%=pagetitle %> <em>-</em></span>Ricerca Immobile</h3>
    <div id="filters">
        <span>Ordina i risultati per: </span>
        <select id="orderby">
            <option value="">-Automatico-</option>
            <option value="data_asc">Data  ↑</option>
            <option value="data_desc">Data  ↓</option>
            <option value="prezzo_asc">Prezzo  ↑</option>
            <option value="prezzo_desc">Prezzo  ↓</option>
            <option value="superficie_asc">Superficie  ↑</option>
            <option value="superficie_desc">Superficie  ↓</option>
            <option value="locali_asc">Locali  ↑</option>
            <option value="locali_desc">Locali  ↓</option>
        </select>
    </div>
    <div class="clearer"></div>
    <ul id="searchresults">
        
    </ul>
   <div class="clearer" style="height: 30px;">
        <span class="loading">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Attendere...</span>
    </div>
    <a id="btnmore" href="#" class="fg-button fg-button-icon-left ui-state-default ui-corner-all">
       <span class="ui-icon ui-icon-signal-diag"></span>carica altri annunci</a>    
</asp:Content>
